﻿Namespace EIBData.DPT
    Public NotInheritable Class EIBDataDPT_21_002
        Inherits EIBDataDPT_21_Base

        Protected _UserStopped As Boolean = Nothing
        Protected _OwnIA As Boolean = Nothing
        Protected _VerifyMode As Boolean = Nothing


        Sub New(data As Byte())
            MyBase.New(data)

            _UserStopped = _valueBase And &H1
            _OwnIA = (_valueBase And &H2) >> 1
            _VerifyMode = (_valueBase And &H4) >> 2
        End Sub

        Sub New(UserStopped As Boolean, OwnIA As Boolean, VerifyMode As Boolean)
            MyBase.New((If(VerifyMode, 1, 0) << 2) + (If(OwnIA, 1, 0) << 1) + If(UserStopped, 1, 0))

            _UserStopped = UserStopped
            _OwnIA = OwnIA
            _VerifyMode = VerifyMode
        End Sub


        Public Overrides Function ToInfoList() As List(Of EIB.InfoBase)
            Dim list As New List(Of EIB.InfoBase)

            list.Add(New EIB.Info("Type", DPT_Name))
            list.Add(New EIB.Info("UserStopped", String.Format("{0} (0x{0:X})", _UserStopped)))
            list.Add(New EIB.Info("OwnIA", String.Format("{0} (0x{0:X})", _OwnIA)))
            list.Add(New EIB.Info("VerifyMode", String.Format("{0} (0x{0:X})", _VerifyMode)))

            Return list
        End Function

        Public Shared Shadows ReadOnly Property DPT_Name As String
            Get
                Return "DPT_Device_Control"
            End Get
        End Property

        Public Shared Shadows ReadOnly Property DPT_Number As String
            Get
                Return "21.002"
            End Get
        End Property

        Public Overrides Function ToString() As String
            Return String.Format("UserStopped: {0}, OwnIA: {1}, VerifyMode: {2}", _UserStopped, _OwnIA, _VerifyMode)
        End Function

        Public Overloads ReadOnly Property OutOfService As Boolean
            Get
                Return _UserStopped
            End Get
        End Property

        Public Overloads ReadOnly Property OwnIA As Boolean
            Get
                Return _OwnIA
            End Get
        End Property

        Public Overloads ReadOnly Property VerifyMode As Boolean
            Get
                Return _VerifyMode
            End Get
        End Property
    End Class
End Namespace